#!/usr/bin/perl
## WWW::Mechanize, XML::RSS,
## WWW::Mechanize - Handy web browsing in a Perl object
use strict;
use warnings;
use Encode qw( encode decode );
use Encode::KR;
use WWW::Mechanize;
use Data::Dumper;
use CGI;
use XML::RSS;

##binmode STDOUT, ":utf8";

## WWW::Mechanize
my $url = "http://www.soccerline.co.kr/news_list/index.php?menu=main";

my $mch = WWW::Mechanize->new();
my $rss = new XML::RSS(version => '2.0', encoding=>"utf-8");
my $cgi = CGI->new();

$cgi->charset('utf-8');
$mch->get( $url ) or die;

## 주소에 /menu=viewbody/ 가 있는 링크
my $res = $mch->find_all_links( url_regex => qr/menu=viewbody/ );

$rss->channel(
	title        => $mch->title(),
	link         => $url,
	description  => sprintf( "RSS Feed for %s ( %s )", $url, scalar(localtime) ) ,
);

foreach my $link( @{$res} ) {
	$rss->add_item(
			title	=> decode("euc-kr", $link->text() ) ,
			link	=> $link->URI()->abs,
	);
}

print $cgi->header("text/xml"), $rss->as_string();

